rm(list=ls())
library(tidyverse)
library(haven)

# Read margin of victory
margin_of_victories <- read_rds(here::here("data","processed","elections","margin_of_victories_1996.rds"))
margin_of_victories <- margin_of_victories %>% 
  rename(year = ano_eleicao)

# Read fiscal outcomes
fiscal_outcomes <- read_rds(here::here("data","processed","fiscalpolicy","fiscal_outcomes_centered.rds"))

fiscal_outcomes_1996 <- fiscal_outcomes %>% 
  filter(year == 1996) %>% 
  select_at(vars(mun_code,year,contains("share")))

# Join all databases

main_database_1996 <- margin_of_victories %>%
  left_join(fiscal_outcomes_1996, by = c("mun_code","year"))

# Save ------
write_dta(main_database_1996,here::here("data","processed","main_database_1996.dta"))


